package test_public;

import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import datamodel.rucksack.Rucksack;
import datamodel.rucksack.RucksackObject;

public class RuckSackTest {
	
	Rucksack rucksack;
	RucksackObject object0 = new RucksackObject(25, 11);
	RucksackObject object1 = new RucksackObject(33, 44);
	RucksackObject object2 = new RucksackObject(50, 88);
	RucksackObject object3 = new RucksackObject(25, 11);
	
	@Before
	public void before() {
		rucksack = new Rucksack(100);
	}

	@Test
	public void testInsert() {
		List<RucksackObject> compareList = new ArrayList<RucksackObject>();
		Assert.assertEquals(compareList, rucksack.getElements());
		
		Assert.assertEquals(true, rucksack.insert(object0));
		compareList.add(object0);
		Assert.assertEquals(compareList, rucksack.getElements());
		Assert.assertEquals(25, rucksack.getValue());
		Assert.assertEquals(11, rucksack.getWeight());
		
		Assert.assertEquals(true, rucksack.insert(object1));
		compareList.add(object1);
		Assert.assertEquals(compareList, rucksack.getElements());
		Assert.assertEquals(58, rucksack.getValue());
		Assert.assertEquals(55, rucksack.getWeight());
		
		Assert.assertEquals(false, rucksack.insert(object2));
		Assert.assertEquals(compareList, rucksack.getElements());
		Assert.assertEquals(58, rucksack.getValue());
		Assert.assertEquals(55, rucksack.getWeight());
	}

	@Test
	public void testRemove() {
		rucksack.insert(object0);
		rucksack.insert(object1);
		rucksack.insert(object3);
		
		Assert.assertEquals(3, rucksack.getElements().size());
		rucksack.remove(object1);
		Assert.assertEquals(2, rucksack.getElements().size());
		Assert.assertTrue(rucksack.getElements().contains(object0));
		Assert.assertTrue(rucksack.getElements().contains(object3));
		Assert.assertFalse(rucksack.getElements().contains(object1));
		
		
	}

	@Test
	public void testEquals() {
		Rucksack compareRucksack = new Rucksack(rucksack);
		Assert.assertEquals(rucksack, compareRucksack);
		
		compareRucksack.insert(object0);
		Assert.assertFalse(rucksack.equals(compareRucksack));

		rucksack.insert(object3);
		Assert.assertFalse(rucksack.equals(compareRucksack));
		
		compareRucksack.insert(object3);
		rucksack.insert(object0);
		Assert.assertEquals(rucksack, compareRucksack);
		
		// Rucksack mit Nicht-Rucksackelement verleichen
		Assert.assertFalse(rucksack.equals(object0));
	}

}
